package com.tm.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Rocky
 * @create 2022-09-26 19:05
 */
//将es核心配置 注入到ioc容器中
@Configuration
public class EsConfig {

    @Value("${elasticsearch.host}")
    private String esHost;

    @Value("${elasticsearch.port}")
    private Integer esPort;

    @Value("${elasticsearch.method}")
    private String esMethod;

    @Bean
    public RestHighLevelClient inintEsHighClient(){
        RestClientBuilder restClientBuilder =
                RestClient.builder(new HttpHost(esHost,esPort,esMethod));
        RestHighLevelClient restHighLevelClient = new RestHighLevelClient(restClientBuilder);
        return restHighLevelClient;
    }
}
